<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>创建一张图片</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="imagick.negateimage.html">« Imagick::negateImage</a></li>
      <li style="float: right;"><a href="imagick.newpseudoimage.html">Imagick::newPseudoImage »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.imagick.html">Imagick</a></li>
    <li>创建一张图片</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="imagick.newimage" class="refentry">
    <div class="refnamediv">
        <h1 class="refname">Imagick::newImage</h1>
        <p class="verinfo">(PECL imagick 2, PECL imagick 3)</p><p class="refpurpose"><span class="refname">Imagick::newImage</span> &mdash; <span class="dc-title">创建一张图片</span></p>

    </div>

    <div class="refsect1 description" id="refsect1-imagick.newimage-description">
        <h3 class="title">说明</h3>
        <div class="methodsynopsis dc-description">
            <span class="modifier">public</span> <span class="methodname"><strong>Imagick::newImage</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$cols</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$rows</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span> <code class="parameter">$background</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$format</code><span class="initializer"> = ?</span></span><br>): <span class="type">bool</span></div>

        <p class="para rdfs-comment">
            创建一个 Imagick 图片对象，同时可以附带设置一个 ImagickPixel 值作为其背景色。
        </p>
    </div>


    <div class="refsect1 parameters" id="refsect1-imagick.newimage-parameters">
        <h3 class="title">参数</h3>
        <p class="para">
            <dl>
                
                    <dt>
<code class="parameter">cols</code></dt>

                    <dd>

                        <p class="para">
                            新建图片对象列的值（宽多少像素）
                        </p>
                    </dd>

                
                
                    <dt>
<code class="parameter">rows</code></dt>

                    <dd>

                        <p class="para">
                            新建图片对象行的值（高多少像素）
                        </p>
                    </dd>

                
                
                    <dt>
<code class="parameter">background</code></dt>

                    <dd>

                        <p class="para">
                            新建图片独享的背景色
                        </p>
                    </dd>

                
                
                    <dt>
<code class="parameter">format</code></dt>

                    <dd>

                        <p class="para">
                            图片格式。这个参数是在 Imagick 2.0.1 版本添加的。
                        </p>
                    </dd>

                
            </dl>

        </p>
    </div>


    <div class="refsect1 returnvalues" id="refsect1-imagick.newimage-returnvalues">
        <h3 class="title">返回值</h3>
        <p class="para">
            成功时返回 <strong><code>true</code></strong>。
        </p>
    </div>


    <div class="refsect1 errors" id="refsect1-imagick.newimage-errors">
        <h3 class="title">错误／异常</h3>
        <p class="para">
            错误时抛出 ImagickException。
        </p>
    </div>


    <div class="refsect1 changelog" id="refsect1-imagick.newimage-changelog">
        <h3 class="title">更新日志</h3>
        <p class="para">
            <table class="doctable informaltable">
                
                    <thead>
                        <tr>
                            <th>版本</th>
                            <th>说明</th>
                        </tr>

                    </thead>

                    <tbody class="tbody">
                        <tr>
                            <td>PECL imagick 2.1.0</td>
                            <td>
                                现在可以似乎用了一个字符串作为颜色传入第三个参数。在此之前的版本只允许以一个 ImagickPixel 对象的形式传入。
                            </td>
                        </tr>

                    </tbody>
                
            </table>

        </p>
    </div>


    <div class="refsect1 examples" id="refsect1-imagick.newimage-examples">
        <h3 class="title">范例</h3>
        <p class="para">
            <div class="example" id="example-2825">
                <p><strong>示例 #1 Using <span class="function"><strong>Imagick::newImage()</strong></span>:</strong></p>
                <div class="example-contents"><p>
                    Create a new image and display it.
                </p></div>
                <div class="example-contents">
                    <div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$image&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">Imagick</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$image</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">newImage</span><span style="color: #007700">(</span><span style="color: #0000BB">100</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">100</span><span style="color: #007700">,&nbsp;new&nbsp;</span><span style="color: #0000BB">ImagickPixel</span><span style="color: #007700">(</span><span style="color: #DD0000">'red'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">$image</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setImageFormat</span><span style="color: #007700">(</span><span style="color: #DD0000">'png'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">header</span><span style="color: #007700">(</span><span style="color: #DD0000">'Content-type:&nbsp;image/png'</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">$image</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
                </div>

            </div>
        </p>
    </div>


</div></div></div></body></html>